package com.javaee.request;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import javax.servlet.*;
import javax.servlet.http.*;

/**
 * <h1>获取请求消息头信息
 * <li>直接从request对象中获取相应的数据即可使用
 * <li>由此，可以逆推，请求过来的时候，带上了许多数据，不光只是用户参数
 * <li>而这些信息，在发请求的浏览器中也可以看到
 * <li>那么，请思考，这些信息获取息可以做什么呢？
 * 
 * @author fhzheng
 *
 */
public class RequestHeadersServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter out = response.getWriter();
		response.setContentType("text/html");
		// 枚举类型的应用
		Enumeration headerNames = request.getHeaderNames();
		while (headerNames.hasMoreElements()) {
			String headerName = (String) headerNames.nextElement();
			out.print(headerName + " : " + request.getHeader(headerName) + "<br />");
		}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
}
